package classes;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;



public class DataSource {
	
	private static String url;
	private static String username;
	private static String password;
	
	
	public static void init()
		throws IOException, ClassNotFoundException
	{
		String fileName = System.getProperty("user.dir") + "/bin/database.properties";
		Properties props = new Properties();
		FileInputStream in = new FileInputStream(fileName);
		props.load(in);
		
		String driver = props.getProperty("jdbc.driver");
		url = props.getProperty("jdbc.url");
		username = props.getProperty("jdbc.username");
		password = props.getProperty("jdbc.password");
		
		Class.forName(driver);		
	}
	
	public static Connection getConnection()
		throws SQLException
	{
		return DriverManager.getConnection(url, username, password);
	}

}
